/* -*- Mode: c; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
/*
  RefObject (http://code.google.com/p/refobject/)
  Copyright (C) 2010-2011 MIURA Shirow (sharow)
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <setjmp.h>
#include <cmockery.h>

#include <RefObject/RefAllocator.h>
#include "test_common.h"


static void
test_RefAllocator0(void **state)
{
    RefObject *robj;
    robj = RefAllocator_CreateFromStdCMallocFree(malloc, free);
    assert_true(robj);
    assert_true(RefObject_DecRef(robj) == 1);
}

static void
test_RefAllocator1(void **state)
{
    RefObject *robj;
    int *pint;
    robj = RefAllocator_CreateFromStdCMallocFree(malloc, free);
    assert_true(robj);
    pint = RefAllocator_Alloc(robj, sizeof(*pint));
    *pint = 0;
    RefAllocator_Free(robj, pint);
    RefObject_DecRef(robj);
}

int
test_RefAllocator(void)
{
    const UnitTest tests[] = {
        unit_test(null_test_success),
        unit_test(test_RefAllocator0),
        unit_test(test_RefAllocator1)
    };
    return run_tests(tests);
}
